package com.l.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 将Json对象转换成Map
 * 
 * @param jsonObject
 *            json对象
 * @return Map对象
 * @throws JSONException
 */
public class JsonToMap {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static Map toMap(String jsonString) throws JSONException {
		JSONObject jsonObject = new JSONObject(jsonString);
		Map result = new HashMap();
		Iterator iterator = jsonObject.keys();
		String key = null;
		String value = null;
		while (iterator.hasNext()) {
			key = (String) iterator.next();
			// value = jsonObject.getString(key);
			value = jsonObject.get(key).toString();
			result.put(key, value);
		}
		return result;

	}
}
